/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.publics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.publics.Supplier;

/**
 *
 * @author jay
 */
public class SupplierTM extends AbstractTableModel {
    
  //  private static final long serialVersionUID = 1L;
    private List<Supplier> data;

    public SupplierTM(List<Supplier> data) {
        this.data = data;
    }

    public SupplierTM() {
        this(new ArrayList<Supplier>(0));
    }

    public Supplier get(int index) {
        return data.get(index);
    }

    public void add(Supplier product) {
        data.add(product);
        fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
    }

    public void remove(int index) {
        data.remove(index);
        fireTableRowsDeleted(index, index);
    }

    public void set(int index, Supplier product) {
        data.set(index, product);
        fireTableRowsUpdated(index, index);
    }

    public void clear() {
        data.clear();
        fireTableDataChanged();
    }

    public void add(Collection<Supplier> products) {
        data.addAll(products);
        fireTableRowsInserted(getRowCount() - (products.size()), getRowCount() - 1);
    }
    
    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return 10;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0: return rowIndex+1;
            case 1: return data.get(rowIndex).getKode();
            case 2: return data.get(rowIndex).getNama();
            case 3: return data.get(rowIndex).getAlamat();
            case 4: return data.get(rowIndex).getKota();
            case 5: return data.get(rowIndex).getPhone();
            case 6: return data.get(rowIndex).getFax();
            case 7: return data.get(rowIndex).getEmail();
            case 8: return data.get(rowIndex).getKontak();
            default: return null;
        }
    }
    
    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0: return "NO";
            case 1: return "KODE";
            case 2: return "NAMA";
            case 3: return "ALAMAT";
            case 4: return "KOTA";
            case 5: return "PHONE";
            case 6: return "FAX";
            case 7: return "EMAIL";
            case 8: return "KONTAK";
            default: return null;
        }
    }
    
}
